package com.lolc.ihm.component;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;

import com.lolc.LoLAutoCounterManager;
import com.lolc.bean.Champion;
import com.lolc.ihm.Constants;
import com.lolc.ihm.listener.SaveChampionListener;
import com.lolc.utils.Constant;

public class BannedChampionsBox extends Box{

	private List<JComboBox<ComboBoxItem>> championsCBlist;
	protected JLabel iconClearOn;
	protected JLabel iconClearOff;
	
	public BannedChampionsBox(int axis) {
		//axis : 
		super(axis);
		// TODO Auto-generated constructor stub
		this.championsCBlist=new ArrayList<JComboBox<ComboBoxItem>>();
	}
		
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void initComponents(int x, int y, int width, int height, int spaceBefore, String group)
	{
		this.setBorder(new LineBorder(Constants.COLOR_GRAY_2, 1));
		
		//Set position
		this.setBounds(x, y, width, height);
		
		Box titleBox = Box.createHorizontalBox();
		this.add(titleBox);
		
		JLabel titleLabel = new JLabel(Constants.BANNED_CHAMPIONS_TITLE);
		titleBox.add(titleLabel);
		titleLabel.setForeground(Color.WHITE);
		titleLabel.validate();
		titleBox.validate();
				
		Box mainBox = Box.createVerticalBox();
		this.add(mainBox);
		
		//Space between title and first list
		Component horizontalGlue = Box.createHorizontalGlue();
		horizontalGlue.setPreferredSize(new Dimension(0,Constants.BANNED_CHAMPIONS_HORIZONTAL_SEPARATOR_HEIGHT));
		mainBox.add(horizontalGlue);
		
		for(int i=0;i<Constant.NUMBER_BANNED_CHAMPIONS_PER_TEAM;i++)
		{			
			Box box = Box.createHorizontalBox();
			mainBox.add(box);

			//Space before the list
			Component verticalGlue = Box.createVerticalGlue();
			verticalGlue.setPreferredSize(new Dimension(spaceBefore, 0));
			box.add(verticalGlue);

			//ConboBox with champion names
			JComboBox<ComboBoxItem> championCB=new JComboBox<ComboBoxItem>();
			championCB.setPreferredSize(new Dimension(Constants.ENNEMY_TEAM_WIDTH,Constants.COMBOBOX_HEIGHT));
			box.add(championCB);
			for(Champion champion : LoLAutoCounterManager.getInstance().getChampionsList())
			{
				championCB.addItem(new ComboBoxItem(champion.getId(), champion.getName()));
			}			
			championCB.setSelectedItem(null);
			AutoCompletion.enable(championCB);
			championCB.addActionListener(new SaveChampionListener(group,i));
			championCB.validate();
			
			//Space after the list
			Component verticalGlue2 = Box.createVerticalGlue();
			verticalGlue2.setPreferredSize(new Dimension(spaceBefore, 0));
			box.add(verticalGlue2);

			/**
			 * TODO add clear button
			 */
			 
			//Vertical space after the list
			Component verticalGlue3 = Box.createVerticalGlue();
			verticalGlue3.setPreferredSize(new Dimension(spaceBefore, 0));
			box.add(verticalGlue3);
				
			//Horizontal space between 2 lines
			Component horizontalGlue2 = Box.createHorizontalGlue();
			horizontalGlue2.setPreferredSize(new Dimension(0,Constants.BANNED_CHAMPIONS_HORIZONTAL_SEPARATOR_HEIGHT));
			mainBox.add(horizontalGlue2);
			
			this.championsCBlist.add(championCB);
			box.validate();
		}
		
		mainBox.validate();
		
		this.validate();
	}
		
	/**
	 * @return the championsCBlist
	 */
	public List<JComboBox<ComboBoxItem>> getChampionsCBlist() {
		return championsCBlist;
	}

	/**
	 * @param championsCBlist the championsCBlist to set
	 */
	public void setChampionsCBlist(List<JComboBox<ComboBoxItem>> championsCBlist) {
		this.championsCBlist = championsCBlist;
	}	
}
